import numpy as np
import math
#正类样本:增广矩阵
x1 = np.array([[1, 1, 1], [1, 2, 1], [2, 2, 1], [1, 0, 1]])
x0 = np.array([[4, 5, 1], [5, 6, 1], [6, 7, 1], [6, 6, 1]])

iter = 1000
w = np.array([0, 0, 0])
lr = 1

for i in range(iter):
    grad = np.zeros(3)
    for j in range(4):
        grad += (1 - math.exp(np.matmul(w, x1[j])) / (1 + math.exp(np.matmul(w, x1[j])))) * x1[j]
        grad -= math.exp(np.matmul(w, x0[j])) / (1 + math.exp(np.matmul(w, x0[j]))) * x0[j]
    w = w + lr * grad

print(w)